﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            var control = Page.LoadControl("~/leftColumn.ascx");
            PlaceHolder1.Controls.Add(control);

            SqlCommand cmdSearch;
            SqlDataReader dtrSearch;
            conn.Open();

            cmdSearch = new SqlCommand("Select a_link, a_picture From Advertisements Where a_status='published'", conn);
            dtrSearch = cmdSearch.ExecuteReader();

            ItemList.DataSource = dtrSearch;
            ItemList.DataBind();

            dtrSearch.Close();
            conn.Close();

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Session["searchText"] = txtSearch.Text;
            Response.Redirect("SearchResult.aspx");
        }

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }
    }
}
